<template>
  <div class="about" :class="{ 'margin-left': !$store.state.ml }">
    <div class="content-container">
      <!-- 功能 -->
      <div class="search">
        <el-row>
          <span class="searchtitle">名称</span>

          <el-input
            class="input"
            v-model="input"
            placeholder="属性名称"
          ></el-input>
          <span class="searchtitle">分类</span>

          <el-input v-model="input3" class="eeeinput">
            <el-select
              class="dw"
              v-model="select"
              slot="prepend"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="(item, index) in newarr1"
                :label="item.value"
                :value="item.value"
                :key="index"
              ></el-option>
            </el-select>
          </el-input>

          <el-button @click="query" class="btn btn1" type="primary"
            >查询</el-button
          >
          <el-button @click="addbrand" class="btn" type="primary"
            >添加</el-button
          >
        </el-row>
      </div>

      <!-- 内容 -->
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column fixed prop="id" label="ID" width="290">
        </el-table-column>
        <el-table-column prop="name" label="品牌名称" width="290">
        </el-table-column>
        <el-table-column prop="floor_price" label="最低价" width="290">
        </el-table-column>
        <el-table-column prop="is_new" label="新品" width="290">
          <template v-slot="scope">
            {{ scope.row.is_new ? "是" : "否" }}
          </template>
        </el-table-column>
        <el-table-column prop="is_show" label="显示" width="290">
          <template v-slot="scope">
            {{ scope.row.is_show ? "是" : "否" }}
          </template>
        </el-table-column>

        <el-table-column label="操作" width="220">
          <template slot-scope="scope">
            <el-button type="text" size="small">
              <el-button
                @click="handleEdit(scope.row)"
                class="btn"
                type="primary"
                >编辑</el-button
              >
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="block">
        <span class="demonstration"></span>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="count"
        >
        </el-pagination>
      </div>
    </div>

    <div class="flex bottom">
      <p>
        <b>Copyright © 2016-2019 </b> <span class="qdl">叩丁狼</span>. All
        rights reserved.
      </p>
      <p><b>Version</b> 1.0.0</p>
    </div>
  </div>
</template>

<script>
import { getattributeapi } from "../request/httpApi";
export default {
  methods: {
    handleEdit(row) {
      // console.log(row.id);
      this.$router.push(`/attributebrand?id=${row.id}`);
    },

    addbrand() {
      this.$router.push("/attributeadd");
    },
    query() {
      getattributeapi({
        page: "1",
        name: this.input,
        c_id: this.select,
        size: "10",
      }).then((okk) => {
        // console.log(okk);
        // console.log(okk.data.count);
        this.tableData = okk.data.data;
        this.count = okk.data.count;
      });
    },
    handleClick(row) {
      console.log(row);
    },
    handleSizeChange(val) {
      this.handleSize = val;
      console.log(`每页 ${val} 条`);
      getbrandapi({
        page: this.handleCurrent,
        name: this.input,
        size: this.handleSize,
      }).then((okk) => {
        // console.log(okk);
        // console.log(okk.data.count);
        this.tableData = okk.data.data;
        this.count = okk.data.count;
      });
    },
    handleCurrentChange(val1) {
      this.handleCurrent = val1;
      // console.log(`当前页: ${val1}`);
      getbrandapi({
        page: this.handleCurrent,
        name: this.input,
        size: this.handleSize,
      }).then((okk) => {
        // console.log(okk);
        // console.log(okk.data.count);
        this.tableData = okk.data.data;
        this.count = okk.data.count;
      });
    },

    arr() {
      console.log(this.newarr1[0].value);

      console.log(this.loadAll());
      this.restaurants = this.newarr1;
    },
  },

  created() {
    getattributeapi({
      page: "1",
      name: "",
      size: "10",
      c_id: null,
    }).then((okk) => {
      console.log(okk);

      //   console.log(okk.data.data);
      //   console.log(okk.data.data[0].attribute_category_id);
      this.tableData = okk.data.data;
      this.count = okk.data.count;
    });
    getattributeapi({
      page: "1",
      name: "",
      size: "10000",
      c_id: null,
    }).then((okk) => {
      let arr = okk.data.data;
      let newarr = arr.map((e) => {
        // console.log(e);
        // console.log(e.attribute_category_id);
        // console.log(obj[value]);
        let obj = {
          value: e.attribute_category_id + "",
          address: e.attribute_category_id + "",
        };
        // console.log(obj);
        return obj;
        // obj[value] = e.attribute_category_id;
      });
      var unique = {};
      newarr.forEach(function (gpa) {
        unique[JSON.stringify(gpa)] = gpa;
      });
      newarr = Object.keys(unique).map(function (u) {
        return JSON.parse(u);
      });
      this.newarr1 = newarr;
    });
  },

  data() {
    return {
      handleSize: 10,
      handleCurrent: 1,
      input: "",
      count: 0,
      currentPage4: 1,
      tableData: [],
      restaurants: [],
      state: "",
      timeout: null,
      iiid: null,
      optiontitle: "",
      newarr1: [],
      input1: "",
      input2: "",
      input3: "",
      select: "",
    };
  },
};
</script>


<style lang = "less" scoped>
.eeeinput {
  margin-right: 165px;
  margin-left: 10px;
  width: 0px;
  position: relative;
  .dw {
    position: absolute;
    top: 10px;
    left: 10px;
    border: 1px solid #dcdfe6;
    background-color: #fff;
    width: 200px;
    overflow: hidden;
  }
}

.search {
  margin: 10px 0 15px;
  .searchtitle {
    font-size: 14px;
    margin-right: 10px;
  }
  .input {
    width: 200px;
    margin-right: 10px;
    /* height: 32px;
    line-height: 32px; */
  }
}
.btn1 {
  margin-left: 10px;
}
</style>
